{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.datasets import fetch_california_housing as fch  #加州房屋价值的数据集"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "[('MedInc', 0.43570282207376665),\n ('HouseAge', 0.009353333142159121),\n ('AveRooms', -0.10423644787475006),\n ('AveBedrms', 0.6309049273927703),\n ('Population', -5.617942040616617e-06),\n ('AveOccup', -0.005155317609499691),\n ('Latitude', -0.42021558233541956),\n ('Longitude', -0.43237754995151517)]"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature = fch().data\n",
    "target = fch().target\n",
    "#数据集的拆分\n",
    "x_train, x_test, y_train, y_test = train_test_split(feature, target, test_size=0.1, random_state=2022)\n",
    "#引入模型\n",
    "linner = LinearRegression()\n",
    "linner.fit(x_train, y_train)\n",
    "#返回的是 w的系数\n",
    "linner.coef_\n",
    "#默认的截距\n",
    "linner.intercept_\n",
    "#值越大 对我们的数据的影响越大\n",
    "[*zip(fch().feature_names, linner.coef_)]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "array([[  1.,   5.,  10.,  25.,  50., 100.]])"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.preprocessing import PolynomialFeatures\n",
    "import matplotlib.pyplot as plt\n",
    "# x = np.array([1, 2, 3, 4, 5, 6, 7])\n",
    "# y=x**2\n",
    "# plt.plot(x,y)\n",
    "c = [[5, 10]]\n",
    "pl = PolynomialFeatures(degree=2)\n",
    "b = pl.fit_transform(c)\n",
    "b\n",
    "#帮助我们进行转换 [1,a,b,a^2,ab,b^2]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "data": {
      "text/plain": "{'data': array([[ 0.,  0.,  5., ...,  0.,  0.,  0.],\n        [ 0.,  0.,  0., ..., 10.,  0.,  0.],\n        [ 0.,  0.,  0., ..., 16.,  9.,  0.],\n        ...,\n        [ 0.,  0.,  1., ...,  6.,  0.,  0.],\n        [ 0.,  0.,  2., ..., 12.,  0.,  0.],\n        [ 0.,  0., 10., ..., 12.,  1.,  0.]]),\n 'target': array([0, 1, 2, ..., 8, 9, 8]),\n 'frame': None,\n 'feature_names': ['pixel_0_0',\n  'pixel_0_1',\n  'pixel_0_2',\n  'pixel_0_3',\n  'pixel_0_4',\n  'pixel_0_5',\n  'pixel_0_6',\n  'pixel_0_7',\n  'pixel_1_0',\n  'pixel_1_1',\n  'pixel_1_2',\n  'pixel_1_3',\n  'pixel_1_4',\n  'pixel_1_5',\n  'pixel_1_6',\n  'pixel_1_7',\n  'pixel_2_0',\n  'pixel_2_1',\n  'pixel_2_2',\n  'pixel_2_3',\n  'pixel_2_4',\n  'pixel_2_5',\n  'pixel_2_6',\n  'pixel_2_7',\n  'pixel_3_0',\n  'pixel_3_1',\n  'pixel_3_2',\n  'pixel_3_3',\n  'pixel_3_4',\n  'pixel_3_5',\n  'pixel_3_6',\n  'pixel_3_7',\n  'pixel_4_0',\n  'pixel_4_1',\n  'pixel_4_2',\n  'pixel_4_3',\n  'pixel_4_4',\n  'pixel_4_5',\n  'pixel_4_6',\n  'pixel_4_7',\n  'pixel_5_0',\n  'pixel_5_1',\n  'pixel_5_2',\n  'pixel_5_3',\n  'pixel_5_4',\n  'pixel_5_5',\n  'pixel_5_6',\n  'pixel_5_7',\n  'pixel_6_0',\n  'pixel_6_1',\n  'pixel_6_2',\n  'pixel_6_3',\n  'pixel_6_4',\n  'pixel_6_5',\n  'pixel_6_6',\n  'pixel_6_7',\n  'pixel_7_0',\n  'pixel_7_1',\n  'pixel_7_2',\n  'pixel_7_3',\n  'pixel_7_4',\n  'pixel_7_5',\n  'pixel_7_6',\n  'pixel_7_7'],\n 'target_names': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),\n 'images': array([[[ 0.,  0.,  5., ...,  1.,  0.,  0.],\n         [ 0.,  0., 13., ..., 15.,  5.,  0.],\n         [ 0.,  3., 15., ..., 11.,  8.,  0.],\n         ...,\n         [ 0.,  4., 11., ..., 12.,  7.,  0.],\n         [ 0.,  2., 14., ..., 12.,  0.,  0.],\n         [ 0.,  0.,  6., ...,  0.,  0.,  0.]],\n \n        [[ 0.,  0.,  0., ...,  5.,  0.,  0.],\n         [ 0.,  0.,  0., ...,  9.,  0.,  0.],\n         [ 0.,  0.,  3., ...,  6.,  0.,  0.],\n         ...,\n         [ 0.,  0.,  1., ...,  6.,  0.,  0.],\n         [ 0.,  0.,  1., ...,  6.,  0.,  0.],\n         [ 0.,  0.,  0., ..., 10.,  0.,  0.]],\n \n        [[ 0.,  0.,  0., ..., 12.,  0.,  0.],\n         [ 0.,  0.,  3., ..., 14.,  0.,  0.],\n         [ 0.,  0.,  8., ..., 16.,  0.,  0.],\n         ...,\n         [ 0.,  9., 16., ...,  0.,  0.,  0.],\n         [ 0.,  3., 13., ..., 11.,  5.,  0.],\n         [ 0.,  0.,  0., ..., 16.,  9.,  0.]],\n \n        ...,\n \n        [[ 0.,  0.,  1., ...,  1.,  0.,  0.],\n         [ 0.,  0., 13., ...,  2.,  1.,  0.],\n         [ 0.,  0., 16., ..., 16.,  5.,  0.],\n         ...,\n         [ 0.,  0., 16., ..., 15.,  0.,  0.],\n         [ 0.,  0., 15., ..., 16.,  0.,  0.],\n         [ 0.,  0.,  2., ...,  6.,  0.,  0.]],\n \n        [[ 0.,  0.,  2., ...,  0.,  0.,  0.],\n         [ 0.,  0., 14., ..., 15.,  1.,  0.],\n         [ 0.,  4., 16., ..., 16.,  7.,  0.],\n         ...,\n         [ 0.,  0.,  0., ..., 16.,  2.,  0.],\n         [ 0.,  0.,  4., ..., 16.,  2.,  0.],\n         [ 0.,  0.,  5., ..., 12.,  0.,  0.]],\n \n        [[ 0.,  0., 10., ...,  1.,  0.,  0.],\n         [ 0.,  2., 16., ...,  1.,  0.,  0.],\n         [ 0.,  0., 15., ..., 15.,  0.,  0.],\n         ...,\n         [ 0.,  4., 16., ..., 16.,  6.,  0.],\n         [ 0.,  8., 16., ..., 16.,  8.,  0.],\n         [ 0.,  1.,  8., ..., 12.,  1.,  0.]]]),\n 'DESCR': \".. _digits_dataset:\\n\\nOptical recognition of handwritten digits dataset\\n--------------------------------------------------\\n\\n**Data Set Characteristics:**\\n\\n    :Number of Instances: 1797\\n    :Number of Attributes: 64\\n    :Attribute Information: 8x8 image of integer pixels in the range 0..16.\\n    :Missing Attribute Values: None\\n    :Creator: E. Alpaydin (alpaydin '@' boun.edu.tr)\\n    :Date: July; 1998\\n\\nThis is a copy of the test set of the UCI ML hand-written digits datasets\\nhttps://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits\\n\\nThe data set contains images of hand-written digits: 10 classes where\\neach class refers to a digit.\\n\\nPreprocessing programs made available by NIST were used to extract\\nnormalized bitmaps of handwritten digits from a preprinted form. From a\\ntotal of 43 people, 30 contributed to the training set and different 13\\nto the test set. 32x32 bitmaps are divided into nonoverlapping blocks of\\n4x4 and the number of on pixels are counted in each block. This generates\\nan input matrix of 8x8 where each element is an integer in the range\\n0..16. This reduces dimensionality and gives invariance to small\\ndistortions.\\n\\nFor info on NIST preprocessing routines, see M. D. Garris, J. L. Blue, G.\\nT. Candela, D. L. Dimmick, J. Geist, P. J. Grother, S. A. Janet, and C.\\nL. Wilson, NIST Form-Based Handprint Recognition System, NISTIR 5469,\\n1994.\\n\\n.. topic:: References\\n\\n  - C. Kaynak (1995) Methods of Combining Multiple Classifiers and Their\\n    Applications to Handwritten Digit Recognition, MSc Thesis, Institute of\\n    Graduate Studies in Science and Engineering, Bogazici University.\\n  - E. Alpaydin, C. Kaynak (1998) Cascading Classifiers, Kybernetika.\\n  - Ken Tang and Ponnuthurai N. Suganthan and Xi Yao and A. Kai Qin.\\n    Linear dimensionalityreduction using relevance weighted LDA. School of\\n    Electrical and Electronic Engineering Nanyang Technological University.\\n    2005.\\n  - Claudio Gentile. A New Approximate Maximal Margin Classification\\n    Algorithm. NIPS. 2000.\\n\"}"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.datasets import load_digits\n",
    "from sklearn.model_selection import train_test_split\n",
    "data=load_digits()\n",
    "data"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}